登录 白背景

1446. 连续字符

https://leetcode-cn.com/problems/consecutive-characters/

  • 提交时间:2021-12-01 02:27:36
  • 执行用时:0 ms, 在所有 Go 提交中击败了100.00%的用户
  • 内存消耗:2.3 MB, 在所有 Go 提交中击败了58.00%的用户
  • 通过测试用例:333 / 333
func maxPower(s string) (ans int) {
    lastStr := s[0]
    count := 1
    n := len(s)
    ans = 1
    for i := 1; i < n; i++ {
        if s[i] != lastStr {
            count = 1
            lastStr = s[i]
            continue
        }
        count++
        if count > ans {
            ans = count
        }
    }
    return
}